home *** CD-ROM | disk | FTP | other *** search
/ Suzy B Software 2 / Suzy B Software CD-ROM 2 (1994).iso / extras / programm / mcode_01 / docs / flow.txt < prev    next >
Text File  |  1995-04-27  |  2KB  |  77 lines

  1. File Description     : Document of Program Flow Control
  2. Author             : Stephen McNabb
  3. Creation Date        : 21st February 1995
  4. Last Updated        : 21st Februray 1995
  5.  
  6.     This document describes methods of obtaining high level program
  7. structures within machine code. In a high level language you have ways
  8. of testing a condition and carrying out commands depending on the result.
  9.  
  10. Example
  11.  
  12.     In 'C':    if (x == 1) printf("The value of x is 1\n");
  13.         else printf("The value of x is not 1\n");
  14.         
  15.     All these can be also obtained with machine code. Below is a
  16. description of some of the ways of obtaining these. The high level language
  17. desccription of the methods is not based on a particular language but
  18. instead is psuedo-code.
  19.  
  20.  
  21. if a=1 then s1 else s2
  22. ----------------------
  23.  
  24. This means that if 'a' is equal to '1' then statement 1 will be executed,
  25. otherwise statement 2 will be executed. d0 will store the value of 'a'.
  26.  
  27. if:    cmpi.b    #1,d0        /check if 'a' is 1
  28.     bne    s2        /if not execute statement 2
  29. s1:    .            -+
  30.     .              | Code for statement 1
  31.     .            -+
  32.     bra    exit        /if statement 1 executed the exit
  33. s2:    .            -+
  34.     .              | Code for statement 2
  35.     .            -+
  36. exit:                /exit the if code
  37.     
  38.  
  39. while a=1 do s1
  40. ---------------
  41.  
  42. This means that statement 1 will continue to be executed while 'a' is
  43. equal to '1'. d0 holds the value of 'a'.
  44.  
  45. while:    cmpi.b    #1,d0        /check if 'a' is 1
  46.     bne    exit        /if not then leave while loop
  47.     .            -+
  48.     .             | Code for statement 1
  49.     .            -+
  50.     bra    while        /continue with while loop
  51. exit:                /exit the while code
  52.  
  53. Note: Statement 1 must be capable of changing the value of 'a'.
  54.  
  55.  
  56. for a = 0 to 6 do s1
  57. --------------------
  58.  
  59. This means that statement 1 will be executed 7 times. A will be begin
  60. with a value of 0 and will be incremented each time statement 1 is
  61. executed. When it has the value of 6 then the loop will stop.
  62.  
  63.     clr    d0        /used to hold value of a starting at 0
  64. for:    .            -+
  65.     .             | Code for statement 1
  66.     .            -+
  67.     addq.b     #1,d0        /increment a each time
  68.     cmpi.b    #6,d0        /check if it equal to 6
  69.     ble    for        /if a<=6 then loop again
  70. exit:                /exit the for loop
  71.  
  72.  
  73.     This document will be extended to cover other high level structures,
  74. such as the case statement, in the next issue.
  75.  
  76. *** End of File ***
  77.